package cn.tedu.micro.demo.all.dao.repository;

import cn.tedu.micro.demo.all.dao.mapper.StockMapper;
import cn.tedu.micro.demo.pojo.po.StockPO;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class StockRepositoryImpl implements StockRepository {
    @Autowired
    private StockMapper stockMapper;

    @Override
    public void updateStock(String productCode, Integer count) {
        /*StockPO po=new StockPO();//一切参数 都由po 来封装 包括 set 参数 where条件参数
        po.setProductCode(productCode);
        po.setStock(count);*/
        //set stock=stock-#{stock} where product_code=#{productCode}
        UpdateWrapper updateWrapper=new UpdateWrapper();
        //拼接where条件
        updateWrapper.eq("product_code",productCode);
        //拼接set数据
        updateWrapper.setSql("stock=stock-"+count);
        stockMapper.update(null,updateWrapper);
    }
}
